package pkg

import (
	"context"
	"dubbo.apache.org/dubbo-go/v3/config"
	"iotall/iotcore/api/proxyup"
	"iotall/iotdeal/deal/basedeal"
	"sync"
)
import (
	_ "dubbo.apache.org/dubbo-go/v3/imports"
)

type ProxyUpServerImpl struct {
	proxyup.UnimplementedProxyUpServer
	IDeals sync.Map
}

func (p *ProxyUpServerImpl) Close(ctx context.Context, in *proxyup.CloseReq) (*proxyup.CloseResp, error) {
	var deal, err = basedeal.GetDeal(in.GetCommPortId())
	if err != nil {
		return nil, err
	}
	return deal.CloseFunc(ctx, in)
}
func (p *ProxyUpServerImpl) Up(ctx context.Context, in *proxyup.UpReq) (*proxyup.UpResp, error) {
	var deal, err = basedeal.GetDeal(in.GetCommPortId())
	if err != nil {
		return nil, err
	}
	return deal.UpFunc(ctx, in)
}

var (
	proxyUpServerImpl = &ProxyUpServerImpl{}
)

func init() {
	config.SetProviderService(proxyUpServerImpl)
}
